package org.mogu.control;

import org.mogu.R;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;


/*
 * QQ的对话框
 * @author androidSource@139.com
 * */
public class QqDialog extends Dialog 
		implements View.OnClickListener{
	
	//显示的视图
	private ViewGroup mViewGroup = null;
	private Button btnOk = null;
	private Button btnCancel = null;
	
	
	public QqDialog(Context paramContext, View paramView
			,boolean doubleButton){
	    super(paramContext, R.style.MyDialogStyle);
	    
	    if(doubleButton){
	    	mViewGroup = (ViewGroup)((LayoutInflater)paramContext.
	    			getSystemService("layout_inflater")).inflate(R.layout.qq_dialog_frame, null);
	    	
	    	
	    	btnOk = (Button)mViewGroup.findViewById(R.id.qq_dialog_ok_btn_id);
	    	btnCancel = (Button)mViewGroup.findViewById(R.id.qq_dialog_cancel_btn_id);
	    	btnOk.setOnClickListener(this);
	    	btnCancel.setOnClickListener(this);
	    }else{
	    	mViewGroup = (ViewGroup)((LayoutInflater)paramContext.
	    			getSystemService("layout_inflater")).inflate(R.layout.qq_dialog_frame2, null);
	    	btnOk = (Button)mViewGroup.findViewById(R.id.qq_dialog_ok_btn_id);
	    	btnOk.setOnClickListener(this);
	    }
	    
	    
	    
	    Window localWindow = getWindow();
	    localWindow.setContentView(mViewGroup);
	    
	    
	    float f1 = getContext().getResources().getDisplayMetrics().density;
	    int l = (int)(280.0F * f1 + 0.5F);
	    int i1 = (int)(f1 * 32.0F + 0.5F);
	    int i2 = ((WindowManager)paramContext.getSystemService("window")).getDefaultDisplay().getWidth();
	    if (i2 < l){
	    	i2 -= i1;
	    }
	    getWindow().setLayout(i2, -1);
	    ViewGroup localViewGroup3 = (ViewGroup)mViewGroup.findViewById(R.id.qq_dialog_bottom_viewgroup);
	    ViewGroup.LayoutParams localLayoutParams = new ViewGroup.LayoutParams(-1, -1);
	    localViewGroup3.addView(paramView, localLayoutParams);
	}
	
	
	@Override
	public void onClick(View view){
		
		switch(view.getId()){
			//确定
			case R.id.qq_dialog_ok_btn_id:
				dismiss();
				break;
				
			//取消
			case R.id.qq_dialog_cancel_btn_id:
				dismiss();
				break;
		}
	}
	
}
